package com.yyf.camera_product_plugin.ble;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;


import com.yyf.camera_product_plugin.camera_product_plugin.R;

import java.util.List;

import cn.com.heaton.blelibrary.ble.model.BleDevice;

public class BlueListAdapter extends RecyclerView.Adapter<BlueListAdapter.ViewHolder> {

    private List<BleDevice> dlist;
    private Context context;

    public BlueListAdapter(Context context, List<BleDevice> dlist){
        this.context=context;
        this.dlist=dlist;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_wifi_list, parent,false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        BleDevice bleDevice=dlist.get(position);
        holder.ssid.setText(bleDevice.getBleName());

        holder.ssid.setOnClickListener(view -> onItenClickListener.onItemClick(bleDevice));
    }

    @Override
    public int getItemCount() {
        return dlist.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        private TextView ssid;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ssid=itemView.findViewById(R.id.ssid_tv);
        }
    }

    public void setDlist(List<BleDevice> dlist){
        this.dlist=dlist;
    }



    private onItenClickListener onItenClickListener;

    public void setOnItenClickListener(onItenClickListener onItenClickListener) {
        this.onItenClickListener = onItenClickListener;
    }

    public interface onItenClickListener{
        void onItemClick(BleDevice bleDevice);
    }
}
